]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
messageTray: Add object holding sound for a notification
authorJulian Sparber <julian@sparber.net>
Tue, 13 Feb 2024 18:25:57 +0000 (19:25 +0100)
committerFlorian Müllner <fmuellner@gnome.org>
Sun, 3 Mar 2024 01:33:16 +0000 (01:33 +0000)
A notification can have two ways to specify a sound, via a name of a
sound in the sound theme and/or a file. Therefore introduce an object
that can hold both properties and creates an abstraction over the
different source. This reduces the number of properties for a
notification, which will make it simpler to port it to GObject
properties.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/3173>

js/ui/messageTray.js
js/ui/notificationDaemon.js

index 8e1d1ed1013c6b15ebf02fbc2529c5c1478b1364..c0d7c4a739ea0e01ffca252cac9123ac4bd4491e 100644 (file)
@@ -314,6 +314,25 @@ export const NotificationApplicationPolicy = GObject.registerClass({
     }
 });
 
+export const Sound = GObject.registerClass(
+class Sound extends GObject.Object {
+    constructor(file, themedName) {
+        super();
+
+        this._soundFile = file;
+        this._soundName = themedName;
+    }
+
+    play() {
+        const player = global.display.get_sound_player();
+
+        if (this._soundName)
+            player.play_from_theme(this._soundName, _('Notification sound'), null);
+        else if (this._soundFile)
+            player.play_from_file(this._soundFile, _('Notification sound'), null);
+    }
+});
+
 // Notification:
 // @source: the notification's Source
 // @title: the title
@@ -391,8 +410,7 @@ export const Notification = GObject.registerClass({
         this.forFeedback = false;
         this.bannerBodyText = null;
         this.bannerBodyMarkup = false;
-        this._soundName = null;
-        this._soundFile = null;
+        this.sound = null;
         this._soundPlayed = false;
         this.actions = [];
         this.setResident(false);
@@ -419,8 +437,7 @@ export const Notification = GObject.registerClass({
             bannerMarkup: false,
             clear: false,
             datetime: null,
-            soundName: null,
-            soundFile: null,
+            sound: null,
         });
 
         this.title = title;
@@ -438,10 +455,8 @@ export const Notification = GObject.registerClass({
         if (params.clear)
             this.actions = [];
 
-        if (this._soundName !== params.soundName ||
-            this._soundFile !== params.soundFile) {
-            this._soundName = params.soundName;
-            this._soundFile = params.soundFile;
+        if (this.sound !== params.sound) {
+            this.sound = params.sound;
             this._soundPlayed = false;
         }
 
@@ -495,11 +510,7 @@ export const Notification = GObject.registerClass({
             return;
         }
 
-        let player = global.display.get_sound_player();
-        if (this._soundName)
-            player.play_from_theme(this._soundName, this.title, null);
-        else if (this._soundFile)
-            player.play_from_file(this._soundFile, this.title, null);
+        this.sound?.play(this.title);
     }
 
     // Allow customizing the banner UI:
index 09c1c6b184384a2c711c6544062aa9d2be783914..a47e098605f72bae95a74085178d41a4b9628c62 100644 (file)
@@ -204,8 +204,7 @@ class FdoNotificationDaemon {
             gicon,
             bannerMarkup: true,
             clear: true,
-            soundFile,
-            soundName: hints['sound-name'],
+            sound: new MessageTray.Sound(soundFile, hints['sound-name']),
         });
 
         let hasDefaultAction = false;